package com.jwgf.common;

import android.os.Build;
import android.provider.Settings;

import com.jwgf.smarowindingmachine_unity.logic.MachineParameterSharedPreference;

public class ScreenOffTimeoutControl {
    private static String SCREEN_TIMEOUT = "screen_timeout";
    private static String SCREEN_OFF_DISPLAY = "screen_off_display";

    public static int getTimeout() {
        int timeout = 60;
        if (Build.VERSION.RELEASE.equals("6.0.1")) {
            timeout = Integer.valueOf(MachineParameterSharedPreference.getInstance().getValue(SCREEN_TIMEOUT, String.valueOf(60 * 1000)));
        } else {
            try {
                timeout = Settings.System.getInt(AppContext.getInstance().getContentResolver(),
                        Settings.System.SCREEN_OFF_TIMEOUT);
            } catch (Exception e) {
            }
        }

        return timeout;

    }

    public static void setTimeout(int timeout) {
        if (Build.VERSION.RELEASE.equals("6.0.1")) {
            MachineParameterSharedPreference.getInstance().setValue(SCREEN_TIMEOUT, String.valueOf(timeout));
        } else {
            Settings.System.putInt(AppContext.getInstance().getContentResolver(),
                    Settings.System.SCREEN_OFF_TIMEOUT, timeout);
        }

    }

    public static void setScreenOffDisplay(int isDisplay) {
        MachineParameterSharedPreference.getInstance().setValue(SCREEN_OFF_DISPLAY, String.valueOf(isDisplay));
    }

    public static int getScreenOffDisplay() {
        return Integer.valueOf(MachineParameterSharedPreference.getInstance().getValue(SCREEN_OFF_DISPLAY, "1"));
    }
}
